<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>SYCMS安装</title>
<!-- 调用样式表 -->
<style>
body, input, textarea, select, button {font-family:"Arial", "Microsoft Yahei", "宋体", sans-serif;}
body {font-size:12px; color:#000;}
a {color:#000; text-decoration:none;}
a:focus {outline:0; -moz-outline:none;} /*for ff*/
a:hover {text-decoration:none; color:#e7a920;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,area,blockquote,th,td,p {margin:0; padding:0;}
img, a img, button {border:0;}
table {border-collapse:collapse;}
li {list-style-type:none;}
input, textarea, select, button {outline:none;}
textarea {resize:none; -webkit-appearance:none;}
button[type="submit"], input[type="submit"], input[type="checkbox"], label {cursor:pointer;}
input[type="checkbox"] {vertical-align:middle;}

/*兼容Chrome和Firefox边框样式*/
select {border:1px #ddd solid;}

/*清除苹果默认的select样式*/
select {appearance:none; -moz-appearance:none; -webkit-appearance:none;}

/*清除ie点击链接出现的边框*/
a, area {blr:expression_r(this.onFocus=this.blur());}

/* 让非ie浏览器默认也显示垂直滚动条，防止因滚动条引起的闪烁 */
html {overflow-y:scroll; overflow-x:hidden;}

/*解除Webkit 12号字体限制*/
html {-webkit-text-size-adjust:none;}

body, html {width:100%; overflow-x:hidden; background-color:#f4f4f4;}

.clear {clear:both; height:0 !important; width:0 !important; overflow:hidden; font-size:0;}
.fl, .fi {float:left;}
.fr {float:right;}

/**************************************/

.box {width:816px; margin:0 auto;}
.nav {padding:25px 0px; text-align:center; color:#fff; background-color:#3a6ea5; font-size:25px;}

.step {width:100%; height:65px; overflow:hidden; margin:40px auto; position:relative;}
.step_p {width:272px; float:left; text-align:center; position:relative;}
.step_p .num {width:36px; height:36px; line-height:36px; font-size:24px; font-style:italic; color:#fff; overflow:hidden; border-radius:50%; background-color:#e2e2e2; margin:0 auto; position:relative; z-index:2;}
.step_p p {font-size:16px; color:#999; height:20px; line-height:20px; margin-top:8px; overflow:hidden; position:relative; z-index:2;}
.step_p_on .num {background-color:#3a6ea5;}
.step_p_on p {color:#3a6ea5;}
.step_bor {width:100%; height:14px; background-color:#e2e2e2; overflow:hidden; position:absolute; top:11px; left:136px; z-index:1;}
.step2_on .step_p1 .step_bor {background-color:#3a6ea5;}
.step3_on .step_p1 .step_bor, .step3_on .step_p2 .step_bor {background-color:#3a6ea5;}

.info {padding:10px; background:#eee; border:1px solid #ccc; line-height:200%; color:#555;}
.info_in {padding:20px; background:#fff;}
.info_in .tit {font-size:14px; font-weight:bold; margin-bottom:10px; color:#000;}
.info_in .success {font-size:18px; font-weight:bold; color:green; text-align:center; padding:50px 0;}
.info_in strong {color:#000;}

.copy {width:158px; height:26px; line-height:26px; margin:0px auto; padding:0px 15px; text-align:center; background:#eee; color:#999; border-radius:5px 5px 5px 5px;}
.copy a {color:#999;}

.install_btn {text-align:center; padding:20px 0;}
.install_btn button.gbutton {margin:0 5px;}
.ginput {height:24px;}
button.gbutton, input[type="submit"].gbutton {font-size:12px; box-shadow:inset 0px 0px 2px #fff; -webkit-box-shadow:inset 0px 0px 2px #fff; -moz-box-shadow:inset 0px 0px 2px #fff; padding:0 10px; height:26px; cursor:pointer; min-width:80px;}
button.gbutton_dblue, input[type="submit"].gbutton_dblue {color:#fff; border:1px solid #3a6ea5; background-color:#3a6ea5;}
button.gbutton:active, input[type="submit"].gbutton:active, button.gbutton_dblue:hover, input[type="submit"].gbutton_dblue:hover {
    box-shadow:inset 0px 0px 3px rgba(0,0,0,0.3);
    -o-box-shadow:inset 0px 0px 3px rgba(0,0,0,0.3);
    -webkit-box-shadow:inset 0px 0px 3px rgba(0,0,0,0.3);
    -moz-box-shadow:inset 0px 0px 3px rgba(0,0,0,0.3);}

.table_box {padding-bottom:20px;}
.table_box table {font-size:12px; border-radius:3px; width:100%;}
.table_box table .left {width:150px; text-align:right; padding-right:10px;}
.table_box table th {height:34px; line-height:34px; color:#fff; font-weight:normal; background-color:#ccc;}
.table_box table td {padding:12px 30px; background-color:#fff;}
.table_box .error {color:red; text-align:center; font-size:15px;}
</style>
</head>
<body>

<div class="nav">欢迎使用 SYCMS！</div>

<?php
#[加载字符串处理类]
require_once("class/string.class.php");
$STR = new QG_C_STRING(false,false,false);

$magic_quotes_gpc = get_magic_quotes_gpc();
@extract($STR->format($_POST));
@extract($STR->format($_GET));

if(!isset($step) && !isset($act))
{
	$step = 1;
}

if(isset($act) && $act=="install")
{
	function zychange($str,$type="encode")
	{
		if($type=="encode")
		{
			$str = str_replace(array("&lt;","&gt;","&quot;","&#39;","&amp;","&nbsp;"),array("__lt__","__gt__","__quot__","__#39__","__amp__","__nbsp__"),$str);
		}
		elseif($type=="decode")
		{
			$str = str_replace(array("__lt__","__gt__","__quot__","__#39__","__amp__","__nbsp__"),array("&lt;","&gt;","&quot;","&#39;","&amp;","&nbsp;"),$str);
		}
		return $str;
	}
	function clearsql($content)
	{
		$content = preg_replace("/--(.*)\n/isU","",$content);
		$content = preg_replace("/SET SQL_MODE=(.*);\n/isU","",$content);
		$content = preg_replace("/\/\*(.*)\*\/;\n/isU","",$content);
		$content = zychange($content,"encode");
		$content_arr = explode(";",$content);
		return $content_arr;
	}
	
	if($testdata)
	{
		$sqlfile = "sql_data.sql";
	}
	else
	{
		$sqlfile = "sql.sql";
	}
	if(!file_exists($sqlfile))
	{
		echo "文件不存在";
		exit;
	}
		
	//先连接数据库
	$servername = $hostname;
	$username = $sqluser;
	$userpassword = $sqlpass;
	$connent = new mysqli($servername,$username,$userpassword);
	if($connent->connect_error)
	{
		//数据库连接失败
		header("Location: install.php?step=2&error=1");
	}
	
	if($createdb)
	{
		//创建数据库
		$sql = "create database ".$database."";
		$connent->query($sql);
		if($connent->query($sql)==false)
		{
			//创建数据库失败
			header("Location: install.php?step=2&error=2");
		}
	}
	
	$connent = new mysqli($servername,$username,$userpassword,$database);
	$sqlcon = clearsql(file_get_contents($sqlfile));
	foreach($sqlcon AS $key=>$value)
	{
		$sql = zychange($value,"decode");
		$sql = str_replace(array("zhisheng_"),array($prefix),$sql);
		$connent->query("set names utf8");
		$connent->query($sql);
	}
	header("Location: install.php?step=3");
	exit;
}
?>

<div class="box">
  <div class="step<?php echo " step".$step."_on"?>">
    <div class="step_p step_p1<?php if($step>=1)echo " step_p_on"?>"><div class="num">1</div><p>使用协议</p><div class="step_bor"></div></div>
    <div class="step_p step_p2<?php if($step>=2)echo " step_p_on"?>"><div class="num">2</div><p>配置环境</p><div class="step_bor"></div></div>
    <div class="step_p step_p3<?php if($step>=3)echo " step_p_on"?>"><div class="num">3</div><p>完成安装</p></div>
  </div><!--step-->
  
  <?php
  if($step==1)
  echo '
  <div class="info">
    <div class="info_in">
      <p class="tit">嗨，您好！欢迎使用SYCMS商友网站管理系统。</p>
      <p>在开始前，我们需要您数据库的一些信息，请准备好如下信息：</p>
      <p><strong>数据库名</strong>、<strong>数据库用户名</strong>、<strong>数据库密码</strong>、<strong">数据库主机地址</strong>。</p>
      <p>我们会使用这些信息来创建一个config.php文件。	如果自动创建未能成功，不用担心，您要做的只是将数据库信息填入配置文件。您也可以在文本编辑器中打开config文件夹中的config.php，填入您的信息，并将其另存为utf-8编码格式。</p>
      <p>以上信息您的网站空间服务提供商会给您这些信息。如果您没有这些信息，在继续之前您将需要联系他们。</p>
      <p>如果您准备好了，可以勾选同意软件许可协议后，点击安装按钮开始安装。</p>
    </div>
  </div>
  
  <div class="install_btn"><button class="gbutton gbutton_dblue" type="button" onclick="window.location.href=\'install.php?step=2\'">开始安装</button></div>';
  ?>
  
  <?php
  if($step==2)
  {
  echo '
  <script>
  function copytext(from,to)
  {
    fromval = from.value;
    document.getElementById(to).value=fromval+"_";
  }
  </script>
  <form method="post" action="install.php?act=install">
    <div class="table_box">
      <table class="table">
        <tr><th colspan="2"><strong>MySQL设置</strong></th></tr>';
        if(isset($error))
		{
			if($error==1)
			{
				echo '<tr><td colspan="2"><div class="error">Error: 数据库连接失败</div></td></tr>';
			}
			elseif($error==2)
			{
				echo '<tr><td colspan="2"><div class="error">Error: 创建数据库失败</div></td></tr>';
			}
		}
		echo '
		<tr><td class="left">数据库地址</td><td><input class="ginput" type="text" name="hostname" id="hostname" value="127.0.0.1" /></td></tr>
        <tr><td class="left">MySQL用户名</td><td><input class="ginput" type="text" name="sqluser" id="sqluser" value="root"></td></tr>
        <tr><td class="left">MySQL密码</td><td><input class="ginput" type="text" name="sqlpass" id="sqlpass" value="root"></td></tr>
        <tr>
          <td class="left">MySQL数据库名</td>
          <td><input class="ginput" type="text" name="database" id="database" value="" onchange="copytext(this,\'prefix\')" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="createdb" id="createdb" checked="checked"><label for="createdb">&nbsp;新建数据库&nbsp;&nbsp;</label><input type="checkbox" value="1" name="testdata" id="testdata"><label for="testdata">&nbsp;安装初始数据</label></td>
        </tr>
        <tr>
          <td class="left">表前缀</td>
          <td><input class="ginput" type="text" name="prefix" id="prefix" placeholder="sycms_"> &nbsp;&nbsp;&nbsp;&nbsp;<font color="red">例如&nbsp;&nbsp;sycms_</font></td>
        </tr>
        <tr>
          <td colspan="2">
            <div class="install_btn">
              <button class="gbutton" type="button" onclick="window.location.href=\'install.php?step=1\'">上一步</button>
              <button class="gbutton gbutton_dblue" type="submit">保存数据库信息</button>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </form>';
  }
  ?>
  
  <?php
  if($step==3)
  echo '
  <div class="info">
    <div class="info_in">
      <p class="success">恭喜您，SYCMS已经成功安装完成！</p>
    </div>
  </div>
  <div class="install_btn">
    <button class="gbutton" type="button" onclick="window.open(\'index.php\')">网站前台</button>
    <button class="gbutton gbutton_dblue" type="button" onclick="window.open(\'admin.php\')">网站后台</button>
  </div>';
  ?>
  
  
  
  <div class="copy">Powered by SYCMS</div>
</div><!--box-->

</body>
</html>